import java.util.HashMap;
import java.util.Map;

/**
 * @Author ZhangCuirong
 * @Date 2025/8/13 11:25
 * @description:
 */
public class Solution383 {
    public boolean canConstruct(String ransomNote, String magazine) {
        Map<Character, Integer> countMap = new HashMap<>();
        for (int i = 0; i < magazine.length(); i++) {
            countMap.put(magazine.charAt(i), countMap.getOrDefault(magazine.charAt(i), 0) + 1);
        }
        for (int i = 0; i < ransomNote.length(); i++) {
            countMap.put(ransomNote.charAt(i), countMap.getOrDefault(ransomNote.charAt(i), 0) - 1);
        }
        for (char character : countMap.keySet()) {
            if (countMap.get(character) < 0) {
                return false;
            }
        }
        return true;
    }
}
